package com.rk.jarjuggler.gui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class DirSearchParams {
    public static final String PROPERTY_SEARCH_TEXT = "searchText";
    public static final String PROPERTY_HAS_JAR = "hasJar";
    public static final String PROPERTY_HAS_SOURCE = "hasSource";
    public static final String PROPERTY_HAS_JAVADOC = "hasJavadoc";

    private String searchText;
    private boolean hasJar;
    private boolean hasSource;
    private boolean hasJavadoc;

    private PropertyChangeSupport pcs;

    public DirSearchParams() {
        pcs = new PropertyChangeSupport(this);
    }

    public String getSearchText() {
        return searchText;
    }

    public void setSearchText(String searchText) {
        String oldValue = getSearchText();

        this.searchText = searchText;
        pcs.firePropertyChange(PROPERTY_SEARCH_TEXT, oldValue, searchText);
    }

    public boolean isHasJar() {
        return hasJar;
    }

    public void setHasJar(boolean hasJar) {
        boolean oldValue = isHasJavadoc();

        this.hasJar = hasJar;
        pcs.firePropertyChange(PROPERTY_HAS_JAR, oldValue, hasJar);
    }

    public boolean isHasSource() {
        return hasSource;
    }

    public void setHasSource(boolean hasSource) {
        boolean oldValue = isHasJavadoc();

        this.hasSource = hasSource;
        pcs.firePropertyChange(PROPERTY_HAS_SOURCE, oldValue, hasSource);
    }

    public boolean isHasJavadoc() {
        return hasJavadoc;
    }

    public void setHasJavadoc(boolean hasJavadoc) {
        boolean oldValue = isHasJavadoc();

        this.hasJavadoc = hasJavadoc;
        pcs.firePropertyChange(PROPERTY_HAS_JAVADOC, oldValue, hasJavadoc);
    }

    public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
        pcs.addPropertyChangeListener(propertyChangeListener);
    }

    public boolean hasCriteria() {
        return isHasJar()
                || isHasJavadoc()
                || isHasSource()
                || (getSearchText() != null && getSearchText().length() > 0);
    }
}
